package com.sskj.fca.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.fca.bean.WalletBean;
import com.sskj.fca.http.HttpConfig;
import com.sskj.fca.ui.activity.WalletAddressManagerActivity;

/**
 * Created by QinKang on 2019/1/1.
 */

public class WalletAddressManagerPresenter extends BasePresenter<WalletAddressManagerActivity> {
    /**
     * 获取钱包列表
     *
     * @return
     */
    public void getWalletList() {
        httpService.walletAddressList()
                .execute(new JsonCallBack<HttpData<PageBean<WalletBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<WalletBean>>> response) {
                        HttpData<PageBean<WalletBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData().getList());
                        }
                    }
                });
    }


    /**
     * 删除钱包地址
     */
    public void deleteWallet(String id) {
        httpService.deleteWallet(id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.delSuccess();
                        }
                    }
                });
    }
}
